<template>
  <div class="app-container">
    <el-card class="form-container" shadow="never">
      <el-form ref="salesOrderConfigForm" :model="salesOrderConfig" :rules="salesOrderConfigRules" label-width="150px">
        <el-form-item label="正常订单超过：" prop="orderTimeout">
          <el-input v-model="salesOrderConfig.orderTimeout" class="input-width">
            <template slot="append">分</template>
          </el-input>
          <span class="note-margin">未付款，订单自动关闭</span>
        </el-form-item>
        <el-form-item label="秒杀订单超过：" prop="seckillTimeout">
          <el-input v-model="salesOrderConfig.seckillTimeout" class="input-width">
            <template slot="append">分</template>
          </el-input>
          <span class="note-margin">未付款，订单自动关闭</span>
        </el-form-item>
        <el-form-item label="发货超过：" prop="takeTimeout">
          <el-input v-model="salesOrderConfig.takeTimeout" class="input-width">
            <template slot="append">天</template>
          </el-input>
          <span class="note-margin">未收货，订单自动完成</span>
        </el-form-item>
        <el-form-item label="订单完成超过：" prop="serviceTimeout">
          <el-input v-model="salesOrderConfig.serviceTimeout" class="input-width">
            <template slot="append">天</template>
          </el-input>
          <span class="note-margin">自动结束交易，不能申请售后</span>
        </el-form-item>
        <el-form-item label="订单完成超过：" prop="commentTimeout">
          <el-input v-model="salesOrderConfig.commentTimeout" class="input-width">
            <template slot="append">天</template>
          </el-input>
          <span class="note-margin">自动五星好评</span>
        </el-form-item>
        <el-form-item label="启动审核流程：" prop="enableAudit">
          <el-radio-group v-model="salesOrderConfig.enableAudit" class="input-width">
            <el-radio v-for="option in options.sysYnTypeOptions" :key="option.key" :label="option.label">{{ option.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注：" prop="remark">
          <el-input v-model="salesOrderConfig.remark" type="textarea" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item>
          <el-button v-hasPermission="['order:salesOrderConfig:update']" type="primary" @click="handleSubmit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import SalesOrderConfigApi from '@/api/order/SalesOrderConfigApi'

const defaultSalesOrderConfig = {
  autoAudit: null,
  orderTimeout: null,
  seckillTimeout: null,
  takeTimeout: null,
  serviceTimeout: null,
  commentTimeout: null,
  enableAudit: null
}
export default {
  name: 'SalesOrderConfigForm',
  data() {
    return {
      options: {
        sysYnTypeOptions: this.$constant.sysYnTypeOptions
      },
      salesOrderConfig: Object.assign({}, defaultSalesOrderConfig),
      salesOrderConfigRules: {
      }
    }
  },
  created() {
    this.init()
    this.loadOptions()
  },
  methods: {
    init() {
      SalesOrderConfigApi.myConfig().then(response => {
        this.salesOrderConfig = response.data
      })
    },
    loadOptions() {
    },
    handleSubmit() {
      this.$refs['salesOrderConfigForm'].validate(valid => {
        if (valid) {
          if (this.salesOrderConfig.id) {
            SalesOrderConfigApi.edit(this.salesOrderConfig).then(response => {
              this.$message.success('修改成功')
              this.init()
            })
          } else {
            SalesOrderConfigApi.add(this.salesOrderConfig).then(response => {
              this.$message.success('添加成功')
              this.init()
            })
          }
        }
      })
    }
  }
}
</script>
